<?php

function greengar_check_friend($friendid, $userid, $app) {
//    echo ('c : ' . $userid . ', ' . $response . ' to ' . $friendid);
    $isFriendEntity = greengar_check_relationship($friendid, $userid, $app, FALSE);
    if(!$isFriendEntity) {
        $isFriendEntity = greengar_check_relationship($userid, $friendid, $app, FALSE);
    }
    $isPendingFriendEntity = greengar_check_relationship($friendid, $userid, $app, TRUE);
    $reversPendingEntity = greengar_check_relationship($userid, $friendid, $app, TRUE);

    if ($isFriendEntity || $isPendingFriendEntity || $reversPendingEntity) {
        if ($isFriendEntity) {
            $result = relationshipToArray($isFriendEntity);
            $result['relationship'] = 'both';
        } else if ($isPendingFriendEntity) {
            $result = relationshipToArray($isPendingFriendEntity);
            $result['relationship'] = 'from';
        } else {
            $result = relationshipToArray($reversPendingEntity);
            $result['relationship'] = 'to';
        }
    } else {
        return array(
            'guid' => -1,
            'relationship' => 'none'
        );
    }
    return $result;
}

?>